﻿@using PagedList
@using PagedList.Mvc
@using CodeCamp.Models.Sessions
@using CodeCamp.Models.Shared
@model SessionSearchViewModel
@{
    var grid = new WebGrid(Model.SearchResults, canPage: false, canSort: true);
}

@if ((Model.SearchResults != null) && (Model.SearchResults.Count > 0))
{
    <div id="sessionPager1">
    @Html.PagedListPager(Model.SearchResults,
            page => Url.Action("UnscheduledSessions", new RouteValueDictionary()
        {
            { "Page", page }
        }),
        PagedListRenderOptions.OnlyShowFivePagesAtATime)
    </div>

    @grid.GetHtml(
        tableStyle: "grid-table",
        headerStyle: "grid-head",
        alternatingRowStyle: "grid-alt-row",
        columns: grid.Columns
        (
            grid.Column(
                columnName: "",
                header: "",
                style: "ui-nowrap",
                format: (item) =>
                    {
                        var links = "";
                        links = links + @Html.ActionLink("Detail", "Details", new { id = @item.Id });
                        if (User.IsInRole(CCRoles.RoleNames.BigCheeze) || User.IsInRole(CCRoles.RoleNames.EventContentEditor))
                        {
                            links = links + " | " + @Html.ActionLink("Edit", "Edit", new { id = @item.Id });
                        }
                        return @Html.Raw(links);
                    }
            ),
            grid.Column("StatusStr", "Status"),
            grid.Column(
                columnName: "CreatedUTC",
                header: "Created (UTC)",
                style: "datetime-nowrap",
                format: @<text>@item.CreatedUTC</text>
                ),
            grid.Column("DesiredRoomSize", "Req. size"),
            grid.Column(
                columnName: "Title",
                header: "Title",
                format: @<text>@item.Title</text>
            ),
            grid.Column("Presenters", "Presenters", canSort: false, format: (item) =>
                {
                    var presenters = "";
                    var first = true;
                    
                    foreach (SessionPresenters.Presenter pr in item.Presenters)
                    {
                        if (first)
                        {
                            first = false;
                        }
                        else
                        {
                            presenters = presenters + ", ";
                        }
                        presenters = presenters +
                            @Html.ActionLink(pr.Name, "Details", "Presenters", new { id = pr.Id }, null);
                    }
                    return @Html.Raw(presenters);
                }),
                grid.Column("TagsCSV", "Tags", canSort: false)
        )
    )    
}

@using (Html.BeginForm("UnscheduledSessions", "Sessions", FormMethod.Post))
{
    @Html.ValidationSummary(false)

    <fieldset>
        <legend>Unscheduled Sessions Search</legend>

        <table>
            <tr>
                <td class="editor-field">Title&nbsp;starts&nbsp;with:&nbsp;@Html.EditorFor(x => x.TitleStart)</td>
                <td valign="bottom" rowspan="3">
                    <input name="SearchButton" type="submit" value="Search" /><br />
                    <input name="ClearButton" type="submit" value="Clear" />
                </td>
            </tr>
            <tr>
                <td class="editor-field">Tags contain:&nbsp;@Html.EditorFor(x => x.TagPart)</td>
            </tr>
            @*
            <tr>
                <td class="editor-field">@Html.EditorFor(x => x.IsEventPresenter) Is Event Presenter</td>
            </tr>
            *@
            <tr>
                <td class="editor-field">Rows per page: @Html.EditorFor(x => x.RowsPerPage)</td>
            </tr>
        </table>

    </fieldset>    
}

@Html.HiddenFor(model => model.UTCOffsetMinutes)

<script type="text/jscript" language="javascript">
    ourDate = new Date
    var uom = document.getElementById("UTCOffsetMinutes");
    if (uom != null) {
        uom.value = ourDate.getTimezoneOffset();
    }
</script>    
